<!--
 * Created by PhpStorm.
 * 版权所有: 2019~2022 [ hhygyl ]
 * Date: 2019/8/23-13:09
 * Link: http://luckyadmin.luckyhhy.cn
 * FileName: index.html
 *-->

<!-- 引入基类模板 -->
{extend name='public/base' /}


{block name="search"}

{:widget('forms/search',array('name','搜索','账号模糊搜索'))}

{/block}

{block name="btn"}
<!--按钮区-->
{:widget('forms/Delbtn',array('删除'))}
{:widget('forms/Addbtn',array('添加账号'))}
{:widget('forms/reload')}

{/block}

{block name="table"} <!--表格区-->

<div class="yys-fluid yys-wrapper">
    <div class="layui-row lay-col-space20">
        <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
            <section class="yys-body">
                <div class="yys-body-content clearfix changepwd">
                    <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                        <div class="user-tables">
                            <table id="tableFilter" lay-filter="tableFilter"> </table>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </div>
</div>

{/block}

{block name="js"} <!--js处理区-->

<!--模板-->
<script type="text/html" id="operationTpl">
    {:widget('forms/Editbtn',array('编辑账号'))}
    {:widget('forms/Delbtn',array('删除账号',2))}
</script>

<script>

    layui.use(['element', 'table', 'form', 'jquery', 'laydate','util','lucky'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var laydate = layui.laydate;
        var lucky=layui.lucky;
        var util=layui.util;

        form.render();


        // layer.load(2);
        table.render({
            elem: '#tableFilter',
            url:"{:url('password/index')}",
            //toolbar: '#toolbarDemo',
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:25
                ,limits:[25,30,40,50,60,100]
            },
            // height: 'full-100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {type: 'checkbox'},
                 {field: 'id',  title: 'ID',width:70,sort:true},
                {field: 'name', minWidth: 200, title: '名称'},
                {field: 'username',align: 'center', width: 200, title: '用户名'},
                {field: 'pass',align: 'center', width: 200, title: '密码'},
                {field: 'url', width: 250,align: 'center', title: '地址',templet:function (d) {
                        if (d.url=='' ||d.url==null){
                            return '<font color="green"> 暂无 </font>';
                        }else {
                            return '<font color="orange"> <a href="'+d.url+'" target="_blank">'+d.url+'</a> </font>';
                        }
                    }},
                {field: 'ip_url', width: 150, title: 'Ip地址',align: 'center'},
                {field: 'port', width: 60, title: '端口',align: 'center'},

                {field: 'time_formt', title: '添加时间',align: 'center',width:180},
                {fixed: 'right',templet: '#operationTpl', width: 100, align: 'center', title: '操作'}
            ]],

            done: function (res) {
                layer.closeAll('loading');
            }
        });

        /**
         * 表格搜索
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch("table_id",obj.field); //查询
            return false;
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            // console.log(JSON.stringify(data));
            var _id=parseInt(data.id);
            var layEvent = obj.event;
            if(layEvent==="edit"){
                var urls="/admin/password/EditAccount/id/"+_id;
                lucky.CreateForm("编辑账号",'50%','60%',urls,"table_id");

            }else if(layEvent==="del"){
                lucky.Delete_data(_id,"{:url('password/delete')}","table_id");
            }

        });


        var active = {
            add:function(){
                lucky.CreateForm("添加账号",'50%','60%',"{:url('password/AddAccount')}","table_id");
            },
            del: function(){ //获取选中数据
                var checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                lucky.Delete_data(id,"{:url('password/delete')}","table_id");
            },
            reload: function(){
                lucky.CreateReload("table_id");
            }

        };

        $('.do_btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script >


{/block}